import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { LayerManager } from "../../manager/LayerManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { DataEvent } from "../../events/DataEvent";
import { Global } from "../../../../com/gengine/global/Global";
type int = number;
//class TWFaceBookShower
    
    export  class TWFaceBookShower extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(LayerManager.highestLayer);
            this._pp = new Object /* flash.geom.Point */(0, 0);
            this.setSize(TWFaceBookShower.WinWidth, TWFaceBookShower.WinHeight);
            this.title = "交友區";
            this.titleHeight = 27;
            this._isJSAvailable = flash.external.ExternalInterface.available;
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            if (this._isJSAvailable) 
            {
                flash.external.ExternalInterface.call("createIFrame", TWFaceBookShower.TWFaceBookJSID, this.getURL(), 520, 350, 0, 0);
                this._isCreated = true;
                Dispatcher.addEventListener(EventName.StageResize, this.onStageResizeHandler);
                this.onStageResizeHandler(null);
            }
            return;
        }

        public /* override */ move(arg1: number, arg2: number): void
        {
            super.move(arg1, arg2);
            this.moveTo(arg1 + 17, arg2 + 40);
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            if (this._isJSAvailable) 
            {
                this.removeIFrame();
            }
            return;
        }

        /* internal  */onStageResizeHandler(arg1: DataEvent): void
        {
            if (this._isDraging) 
            {
                return;
            }
            var loc1=Global.stage.stageWidth;
            var loc2=Global.stage.stageHeight;
            this.x = (loc1 - TWFaceBookShower.WinWidth) / 2;
            this.y = (loc2 - TWFaceBookShower.WinHeight) / 2;
            this.updateIFramePlace();
            return;
        }

        protected /* override */ onMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._isDraging = true;
            super.onMouseDownHandler(arg1);
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMyMouseUpHandler);
            if (this._isJSAvailable) 
            {
                this.addEventListener(flash.events.Event.ENTER_FRAME, this.onEveryFrame);
            }
            return;
        }

        protected onEveryFrame(arg1: Object /* flash.events.Event */): void
        {
            this.updateIFramePlace();
            return;
        }

        public /* override */ set x(arg1: number)
        {
            super.x = arg1;
            this.moveTo(arg1 + 17, this.y);
            return;
        }

        public /* override */ set y(arg1: number)
        {
            super.y = arg1;
            this.moveTo(this.x, arg1 + 40);
            return;
        }

        /* internal  */updateIFramePlace(): void
        {
            this._tp = this.localToGlobal(this._pp);
            this.moveTo(this._tp.x + 17, this._tp.y + 40);
            return;
        }

        protected onMyMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.removeEventListener(flash.events.Event.ENTER_FRAME, this.onEveryFrame);
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMyMouseUpHandler);
            this._isDraging = false;
            return;
        }

        public removeIFrame(): void
        {
            if (!this._isCreated || !this._isJSAvailable) 
            {
                return;
            }
            flash.external.ExternalInterface.call("removeFrame", TWFaceBookShower.TWFaceBookJSID);
            return;
        }

        public moveTo(arg1: int, arg2: int): void
        {
            if (!this._isCreated || !this._isJSAvailable) 
            {
                return;
            }
            flash.external.ExternalInterface.call("move", TWFaceBookShower.TWFaceBookJSID, arg1, arg2);
            return;
        }

        public getURL(): string
        {
            if (!this._isJSAvailable) 
            {
                return "http://www.baidu.com";
            }
            var loc1=String(flash.external.ExternalInterface.call("function(){return document.location.href.toString()}"));
            loc1 = loc1.slice(0, loc1.lastIndexOf("/")) + "/html/iframepage1.html";
            return loc1;
        }

        public static get instance(): TWFaceBookShower
        {
            if (TWFaceBookShower._instance == null) 
            {
                TWFaceBookShower._instance = new TWFaceBookShower();
            }
            return TWFaceBookShower._instance;
        }

        public static /* const */TWFaceBookJSID: string="TWFaceBookShower.TWFaceBookJSID";

        /* internal */ static /* const */WinWidth: int=555;

        /* internal */ static /* const */WinHeight: int=400;

        /* internal */ /* var */_isJSAvailable: Boolean;

        /* internal */ /* var */_isCreated: Boolean=false;

        /* internal */ /* var */_isDraging: Boolean=false;

        /* internal */ /* var */_pp: Object /* flash.geom.Point */;

        /* internal */ /* var */_tp: Object /* flash.geom.Point */;

        /* internal */ static /* var */_instance: TWFaceBookShower;
    }
